<template>
  <div class="app-container">
    <div class="container">
      <el-row :gutter="20" class="filter-container">
        <el-col :span="13">
          <el-breadcrumb separator="">
            <el-breadcrumb-item to="/softManage/softManage"><i class="el-icon-arrow-left" style="cursor: pointer;">返回</i></el-breadcrumb-item>
            <!-- <el-breadcrumb-item>软件管理/</el-breadcrumb-item>
            <el-breadcrumb-item v-if="$route.query.secretkey != 'up'">秘钥管理</el-breadcrumb-item>
            <el-breadcrumb-item v-else>查看秘钥</el-breadcrumb-item> -->
          </el-breadcrumb>
        </el-col>
      </el-row>
      <el-row class="margin-top20">
        <el-col :span="13" :offset="1">
          <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm" size="mini">
            <el-form-item label="软件名称:" prop="name">
              <el-input v-model="$route.query.secretkey.name" disabled />
            </el-form-item>
            <el-form-item label="版本:" prop="name">
              <el-input v-model="$route.query.secretkey.version" disabled />
            </el-form-item>
            <el-form-item label="版本:" prop="name">
              <el-input v-model="$route.query.secretkey.typeName" disabled />
            </el-form-item>
            <el-form-item
              v-for="(domain, index) in ruleForm.domains"
              :key="domain.key"
              :inline="true"
              :label="'秘钥' + (index+1)+':'"
              :prop="'domains.' + index + '.value'"
              :rules="{
                message: '秘钥', trigger: 'blur'
              }"
            >
              <el-form :inline="true" class="demo-form-inline" size="mini">
                <el-form-item>
                  <el-input v-model="domain.value" disabled class="el-input-width" />
                </el-form-item>
                <el-form-item v-if="index%2 != 0" label="使用者:">
                  <el-input v-model="domain.value" disabled class="el-input-width" />
                  <el-button type="danger" class="margin-left10" @click.prevent="removeDomain(domain)">
                    回收秘钥
                  </el-button>
                </el-form-item>
                <el-form-item v-else label="使用者:">
                  <el-select v-model="formInline.region" placeholder="请选择使用者" class="el-input-width">
                    <el-option label="无" value="无" />
                    <el-option label="用户1" value="user" />
                  </el-select>
                </el-form-item>
              </el-form>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" style="width:100px;" @click="submitForm('ruleForm')">确认</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        user: '',
        region: '无'
      },
      ruleForm: {
        domains: [
          {
            value: ''
          },
          {
            value: ''
          },
          {
            value: ''
          },
          {
            value: ''
          }
        ],
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '有秘钥',
        desc: ''
      },
      rules: {
        // name: [
        //   { required: true, message: '请输入活动名称', trigger: 'blur' },
        //   { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        // ],
        // region: [
        //   { required: true, message: '请选择活动区域', trigger: 'change' }
        // ],
        // date1: [
        //   { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        // ],
        // date2: [
        //   { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        // ],
        // type: [
        //   { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        // ],
        // resource: [
        //   { required: true, message: '请选择活动资源', trigger: 'change' }
        // ],
        // desc: [
        //   { required: true, message: '请填写活动形式', trigger: 'blur' }
        // ]
      }
    }
  },
  created() {
  },
  methods: {
    removeDomain(item) {
      var index = this.ruleForm.domains.indexOf(item)
      if (index !== -1) {
        this.ruleForm.domains.splice(index, 1)
      }
    },
    addDomain() {
      this.ruleForm.domains.push({
        value: '',
        key: Date.now()
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message.success('操作成功')
          this.$router.push({ path: '/softManage/softwareManage' })
        } else {
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style>
  .margin-left10 {
    margin-left: 10px;
  }
  .el-upload-dragger{
      width: 260px  !important;
  }
</style>
<style scoped>
 .app-container {
    /* background-color: #333333; */
  }
  .container {
      padding-top: 13px;
      background-color: #ffffff !important;
    }
  .el-input-width {
    width: 120px !important;
  }
  .el-upload-dragger{
      width: 260px  !important;
  }
  .el-upload{
    width:280px !important;
  }
  .el-upload {
    width:280px;
  }
  .el-textarea {
    width: 280px;
    height: 122px;
  }
  .margin-top20 {
    margin-top: 20px;
  }
  .el-input{
    width: 180px;
    height: 48px;
  }
  .el-select {
    width: 180px;
    height: 48px;
  }
</style>
